//
//  DiarySaveSuccessView.swift
//  MoodDiary
//
//  Created by ext.tanjian3 on 2022/1/24.
//

import UIKit

class DiarySaveSuccessView: UIView {

    // MARK: Typealias
    typealias DidTouchUpInside = () -> Void
    
    // MARK: - Properties

    private var didTouchUpInsideButton: DidTouchUpInside?

    let comfortImv: UIImageView = {
        let imv = UIImageView()
        imv.image = UIImage(named: "save_success")
        imv.contentMode = .scaleAspectFit
        return imv
    }()
    
    let comfortTitle: UILabel = {
        let lb = UILabel()
        lb.text = "心情数据已保存"
        lb.textAlignment = .center
        lb.textColor = UIColor.hexColor(hex: "#6A6A6A")
        lb.font = UIFont(name: "PingFangSC-Medium", size: 20)
        return lb
    }()
    
    let button: UIButton = {
        let btn = UIButton()
        btn.setTitle("确定", for: .normal)
        btn.titleLabel?.font = UIFont(name: "PingFangSC-Regular", size: 16)
        btn.setTitleColor(.black, for: .normal)
        btn.backgroundColor = .white
        btn.layer.borderWidth = 1.0
        btn.layer.borderColor = UIColor.black.cgColor
        btn.layer.cornerRadius = 19.0
        return btn
    }()
    
    // MARK: - Initializer

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.commonInit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        self.commonInit()
    }

    func commonInit() {
        
        addSubview(comfortImv)
        addSubview(comfortTitle)
        addSubview(button)
        
        button.addTarget(self, action: #selector(tapButton), for: .touchUpInside)
        
        comfortImv.snp.makeConstraints { (maker) in
            maker.width.equalTo(52.0)
            maker.height.equalTo(50.0)
            maker.top.equalToSuperview().offset(50.0)
            maker.centerX.equalToSuperview()
        }
        
        comfortTitle.snp.makeConstraints { (maker) in
            maker.leading.equalToSuperview().offset(48.0)
            maker.trailing.equalToSuperview().offset(-48.0)
            maker.top.equalTo(comfortImv.snp.bottom).offset(40.0)
        }
        
        button.snp.makeConstraints { (maker) in
            maker.top.equalTo(comfortTitle.snp.bottom).offset(35.0)
            maker.centerX.equalToSuperview()
            maker.height.equalTo(38.0)
            maker.width.equalTo(95.0)
        }
    }
    
    @objc func tapButton() {
        self.didTouchUpInsideButton?()
    }
    
    public func didTouchUpInside(action: @escaping DidTouchUpInside) {
        self.didTouchUpInsideButton = action
    }

}
